import SwapPortfolioPosition from '../../common/swap-porfolio-position/swap-portfolio-position.vue'
import AddInvesterPortfolio from '../../common/add-invester-portfolio/add-invester-portfolio.vue'
import InvesterPortfolioItem from '../../common/invester-portfolio-item/invester-portfolio-item.vue'
import Pages from '../../../../pages/pages.vue'
import { getInvesterBetaList, showMsg } from '../../../../../vuex/action.js'
import extend from 'extend'

export default {
  name: 'InvesterPortfolioManage',
  data() {
    return {
      hkGroupList: [],
      pages: {
        start: 0,
        totalPages: 0,
        limit: 99999
      }
    }
  },
  computed: {
    sortGroupList() {
      return this.hkGroupList.sort((item1, item2) => {
        return item1.seq - item2.seq
      })
    }
  },
  methods: {
    showMsg(msg) {
      this.xShowMsg({
        type: 'danger',
        content: msg
      })
    },
    deepClone(obj) {
      return extend(true, {}, obj)
    },
    getList() {
      this.xGetInvesterBetaList({
        start: this.pages.start,
        limit: this.pages.limit,
        type: this.payType
      }).then((res) => {
        this.hkGroupList = res.data.list
      }).catch((res) => {
        this.showMsg(res.error_msg)
      })
    }
  },
  events: {
    on_refresh_list() {
      this.getList()
    }
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xGetInvesterBetaList: getInvesterBetaList
    },
    getters: {
      payType: state => state.payType
    }
  },
  components: {
    'swap-portfolio-position': SwapPortfolioPosition,
    'add-invester-portfolio': AddInvesterPortfolio,
    'invester-portfolio-item': InvesterPortfolioItem,
    'vue-pages': Pages
  },
  ready() {
    this.getList()
  }
}
